<template>
  <div class="app-container">
    <div style="overflow:hidden">
      <el-form style="float:left">
        <el-form-item label="请选择渠道" :label-width="formLabelWidth" class="input">
          <el-select v-model="form.retailersName" placeholder="请选择"  @change="getUserList" >
            <el-option
              v-for="item in options"
              :key="item.id"
              :label="item.retailersName"
              :value="item.retailersName">
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="手机号" :label-width="formLabelWidth" class="input">
          <el-input v-model="form.phoneNum" placeholder="请输入手机号"></el-input>
        </el-form-item>
      </el-form>
      <el-button type="primary" icon="el-icon-search" style="float:left;margin-left:10px" @click="getUserList">查询</el-button>
      <el-button type="danger" icon="el-icon-download" style="float:left;margin-left:10px" @click="userExcel">导出excel</el-button>
    </div>
    <el-table :data="userData" border style="width: 100%" class="actTable">
      <el-table-column prop="phoneNum" label="手机号" min-width="120"></el-table-column>
      <el-table-column prop="balance" label="余额" width="100"></el-table-column>
      <el-table-column prop="create" label="注册时间" min-width="120"></el-table-column>
      <el-table-column prop="retailersName" label="渠道来源"     width="150"></el-table-column>
      <el-table-column prop="rebate" label="累计返利"     width="100"></el-table-column>
      <el-table-column prop="marketingAmonut" label="累计营销费用"  width="120"></el-table-column>
      <el-table-column prop="invitePhoneNum" label="邀请人"       min-width="110"></el-table-column>
      <el-table-column prop="remark" label="备注"         width="100"></el-table-column>
      <el-table-column prop="status" label="状态"         width="100"></el-table-column>
    </el-table>
    <div class="block">
      <el-pagination
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :current-page="curPage"
        :page-sizes="[10, 20, 50, 100]"
        :page-size="pageSize"
        layout="total, sizes, prev, pager, next, jumper"
        :total="size">
      </el-pagination>
    </div>
  </div>
</template>

<script>
import { api, getUserList } from 'api/account'
import { retailersList } from 'api/retailers'
export default {
  data() {
    return {
      userData: [],
      showDialog: false,
      activityId: '',
      form: {
        phoneNum: '',
        retailersName: ''
      },
      formLabelWidth: '120px',
      size: 0,
      pageSize: 10,
      curPage: 1,
      options: []
    }
  },
  created() {
    this.getOnlineList()
    this.getUserList()
  },
  methods: {
    async getOnlineList() {
      const parm = {
        pageSize: 1000,
        curPage: 0
      }
      try {
        let back = await retailersList(parm)
        back = back.data
        if (back.resultCode === '200') {
          this.options = back.result
        }
      } catch (err) {
        this.$alert('请求出错', '提示')
      }
    },
    userExcel() {
      window.location.href = api.userExcel
    },
    async getUserList() {
      const parm = { ...this.form }
      parm.pageSize = this.pageSize
      parm.curPage = this.curPage - 1
      try {
        let back = await getUserList(parm)
        back = back.data
        if (back.resultCode === '200') {
          this.userData = back.result
          this.size = back.size
        } else {
          this.$alert(back.msg, '提示')
        }
      } catch (err) {
        this.$alert('请求出错', '提示')
      }
    },
    handleSizeChange(val) {
      this.pageSize = val
      this.getUserList()
    },
    handleCurrentChange(val) {
      this.curPage = val
      this.getUserList()
    }
  }
}
</script>
<style scoped lang="scss">
  .actTable{
    margin-top:20px;
  }
  .banner {
    width: 200px;
  }
  .input{
    float: left;
  }
  .block{
    float: right;
    margin-top:15px;
  }
</style>
